package com.yizn.service;

import com.spring.BeanPostProcessor;
import com.spring.Component;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * project : my-learn
 * <p>  </p>
 *
 * @author yisl
 * @date 2022-07-22【星期五】
 **/
@Component
public class YiznValueBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        for (Field declaredField : bean.getClass().getDeclaredFields()) {
            if (declaredField.isAnnotationPresent(YiznValue.class)) {
                declaredField.setAccessible(true);
                try {
                    declaredField.set(bean, declaredField.getAnnotation(YiznValue.class).value());
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return bean;
    }
}
